import router from "@/router/index";

const whiteList = ["/login", "/404"];

router.beforeEach((to, from, next) => {
  if (whiteList.includes(to.path)) return next();
  if (to.meta.requireAuth) {
    // 判断该路由是否需要登录权限
    const isLogin = sessionStorage.getItem("loginInfo");
    if (isLogin) {
      next();
    } else {
      next({
        path: "/login",
        query: { redirect: to.fullPath }, // 将跳转的路由path作为参数，登录成功后跳转到该路由
      });
    }
  } else {
    next();
  }
});
